package com.ruoyi.web.controller.teacher;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.BasisReceiver;
import com.ruoyi.dto.BasisPositionFrequencyConverter;
import com.ruoyi.dto.BasisPositionReceiver;
import com.ruoyi.service.IBasisReceiverService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 接收设备名称与接收设备类型关联Controller
 * 
 * @author wangzebing
 * @date 2025-07-05
 */
@RestController
@RequestMapping("/receiver")
public class BasisReceiverController extends BaseController
{
    @Autowired
    private IBasisReceiverService basisReceiverService;

    /**
     * 查询接收设备名称与接收设备类型关联列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BasisReceiver basisReceiver)
    {
        startPage();
        List<BasisReceiver> list = basisReceiverService.selectBasisReceiverList(basisReceiver);
        return getDataTable(list);
    }

    /**
     * 导出接收设备名称与接收设备类型关联列表
     */
    @Log(title = "接收设备名称与接收设备类型关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasisReceiver basisReceiver)
    {
        List<BasisReceiver> list = basisReceiverService.selectBasisReceiverList(basisReceiver);
        ExcelUtil<BasisReceiver> util = new ExcelUtil<BasisReceiver>(BasisReceiver.class);
        util.exportExcel(response, list, "接收设备名称与接收设备类型关联数据");
    }

    /**
     * 获取接收设备名称与接收设备类型关联详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(basisReceiverService.selectBasisReceiverById(id));
    }

    /**
     * 新增接收设备名称与接收设备类型关联
     */
    @Log(title = "接收设备名称与接收设备类型关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasisReceiver basisReceiver)
    {
        basisReceiver.setType("接收设备");
        return toAjax(basisReceiverService.insertBasisReceiver(basisReceiver));
    }

    /**
     * 修改接收设备名称与接收设备类型关联
     */
    @Log(title = "接收设备名称与接收设备类型关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasisReceiver basisReceiver)
    {
        return toAjax(basisReceiverService.updateBasisReceiver(basisReceiver));
    }

    /**
     * 删除接收设备名称与接收设备类型关联
     */
    @Log(title = "接收设备名称与接收设备类型关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(basisReceiverService.deleteBasisReceiverByIds(ids));
    }


    @GetMapping(value = "/removeReceiverById")
    public AjaxResult ReceiverById(BasisPositionReceiver basisPositionReceiver)
    {
        return success(basisReceiverService.deleteBasisReceiverById2(basisPositionReceiver));
    }


    @GetMapping(value = "/findByLoadingIdAndPositionIdFromReceiver")
    public AjaxResult findByLoadingIdAndPositionIdFromReceiver(String loadingId,String positionId)
    {
        return success(basisReceiverService.findByLoadingIdAndPositionId(loadingId, positionId));
    }
}
